package com.burgeon.backend.Rest.Template.Reviews;
/**
 * 创建评价记录
 */

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.entity.Reviews;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;

public class CreateReviews extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public CreateReviews(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符
     */
    public void getData(Reviews data) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(data), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");
        if (!"0".equals(code)) {
            throw new Exception(message);
        }



    }

    private MultiValueMap Data(Reviews data) {

        HashMap params = new HashMap();

        params.put("M_RETAIL_ID__DOCNO", data.getRcode());//零售单号
        params.put("C_VIP_ID__CARDNO", data.getIcode());//vip卡号
        params.put("SCORE1", data.getScore1());//购物环境满意度
        params.put("SCORE2", data.getScore2());//是否向亲朋推荐
        params.put("SCORE3", data.getScore3());//服务水平满意度
        params.put("SCORE4", data.getScore4());//质量水平满意度
        params.put("DESCRIPTION", "'"+data.getDescription()+"'");//意见建议

        params.put("table", "VIP_VALUATION_WX");//表名

        return DATA("ObjectCreate", params, account, password);
    }

    public static void main(String[] args) {
        CreateReviews g = new CreateReviews("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            Reviews reviews = new Reviews();
            reviews.setIcode("17732141036");
            reviews.setRcode("RE2010200000007");
            reviews.setScore1("1");
            reviews.setScore2("1");
            reviews.setScore3("1");
            reviews.setScore4("1");
            g.getData(reviews);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
